home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / mee / vbdao / visdata / dynagrid.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  20.0 KB  |  663 lines

  1. VERSION 2.00
  2. Begin Form fGridFrm 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   3105
  5.    ClientLeft      =   930
  6.    ClientTop       =   3585
  7.    ClientWidth     =   6690
  8.    Height          =   3510
  9.    Icon            =   0
  10.    Left            =   870
  11.    LinkTopic       =   "Form1"
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   3096
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   6708
  16.    Tag             =   "Dynaset"
  17.    Top             =   3240
  18.    Width           =   6810
  19.    Begin Grid cGrid 
  20.       FixedCols       =   0
  21.       FixedRows       =   0
  22.       Height          =   2412
  23.       Left            =   0
  24.       TabIndex        =   0
  25.       Top             =   480
  26.       Width           =   6732
  27.    End
  28.    Begin PictureBox ViewButtons 
  29.       BackColor       =   &H00C0C0C0&
  30.       BorderStyle     =   0  'None
  31.       Height          =   375
  32.       Left            =   0
  33.       ScaleHeight     =   372
  34.       ScaleMode       =   0  'User
  35.       ScaleWidth      =   5171.606
  36.       TabIndex        =   1
  37.       Top             =   24
  38.       Width           =   5175
  39.       Begin CommandButton SortButton 
  40.          Caption         =   "&Sort"
  41.          Height          =   372
  42.          Left            =   3720
  43.          TabIndex        =   9
  44.          Top             =   0
  45.          Width           =   612
  46.       End
  47.       Begin CommandButton FilterButton 
  48.          Caption         =   "Fil&ter"
  49.          Height          =   372
  50.          Left            =   3120
  51.          TabIndex        =   8
  52.          Top             =   0
  53.          Width           =   612
  54.       End
  55.       Begin CommandButton RefreshButton 
  56.          Caption         =   "&Redo"
  57.          Height          =   372
  58.          Left            =   2520
  59.          TabIndex        =   7
  60.          Top             =   0
  61.          Width           =   612
  62.       End
  63.       Begin CommandButton CloseButton 
  64.          Cancel          =   -1  'True
  65.          Caption         =   "&Close"
  66.          Height          =   372
  67.          Left            =   4320
  68.          TabIndex        =   6
  69.          Top             =   0
  70.          Width           =   612
  71.       End
  72.       Begin CommandButton MoreButton 
  73.          Caption         =   "&More"
  74.          Height          =   372
  75.          Left            =   1320
  76.          TabIndex        =   5
  77.          Top             =   0
  78.          Width           =   612
  79.       End
  80.       Begin CommandButton NextButton 
  81.          Caption         =   "&Next"
  82.          Height          =   372
  83.          Left            =   120
  84.          TabIndex        =   4
  85.          Top             =   0
  86.          Width           =   612
  87.       End
  88.       Begin CommandButton FirstButton 
  89.          Caption         =   "&First"
  90.          Height          =   372
  91.          Left            =   720
  92.          TabIndex        =   3
  93.          Top             =   0
  94.          Width           =   612
  95.       End
  96.       Begin CommandButton FindButton 
  97.          Caption         =   "F&ind"
  98.          Height          =   372
  99.          Left            =   1920
  100.          TabIndex        =   2
  101.          Top             =   0
  102.          Width           =   612
  103.       End
  104.    End
  105. Option Explicit
  106. 'form variables
  107. Dim FDS As Dynaset         'current form's dynaset
  108. 'Dim FDS As snapshot        'current form's snapshot
  109. Dim FDynSt As String       'dynaset open string
  110. Dim FTblName As String     'form dynaset table name
  111. Dim FCurrentRow As Long    'current row in dynaset
  112. Dim FGridRow As Integer    'current grid row
  113. Dim FNotFound As Integer   'find not found flag
  114. Dim FFindForm As New fFind 'find form
  115. Dim FNumbRows As Long      'total number of rows in table
  116. Dim FDynaString As String  'dynaset open string
  117. Sub cGrid_DblClick ()
  118.   Dim r As Integer       'return from execute sql
  119.   Dim fn As String       'field name
  120.   Dim bm As String
  121.   Dim c As Integer
  122.   On Error GoTo ZoomErr
  123.   r = cGrid.Row
  124.   cGrid.Row = 0
  125.   'get field name
  126.   fn = cGrid.Text
  127.   cGrid.Row = r
  128.   'check to see if the dynaset is updatable
  129.   If FDS.Updatable = False Then
  130.     'only allow memo fields for browsing
  131.     If FDS(fn).Type <> FT_MEMO Then
  132.       Exit Sub
  133.     End If
  134.   End If
  135.   'make sure it's a string or memo field
  136.   If FDS(fn).Type <> FT_BINARY Then
  137.      gstZoomData = cGrid.Text
  138.      fZoom.Caption = fn
  139.      fZoom.Top = VDMDI.Top + Top + 1200
  140.      fZoom.Left = VDMDI.Left + Left + 250
  141.      If FDS(fn).Type <> FT_MEMO Then
  142.        fZoom.cData = gstZoomData
  143.        fZoom.Height = 1125
  144.      Else
  145.        fZoom.cMemo = gstZoomData
  146.        fZoom.cMemo.Visible = True
  147.        fZoom.cData.Visible = False
  148.        fZoom.Height = 2205
  149.      End If
  150.      If FDS.Bookmarkable And FDS.Updatable Then
  151.        fZoom.SaveButton.Visible = True
  152.        fZoom.CloseButton.Visible = True
  153.      Else
  154.        fZoom.CloseZoomButton.Visible = True
  155.      End If
  156.      fZoom.Show MODAL
  157.   End If
  158.   'update the record
  159.   If FDS.Bookmarkable Then
  160.     If gstZoomData <> "__CANCELLED__" Then
  161.       c = cGrid.Col
  162.       cGrid.Col = cGrid.Cols - 1
  163.       bm = ASCIItoBM((cGrid))
  164.       FDS.Bookmark = bm
  165.       FDS.Edit
  166.       FDS(fn) = gstZoomData
  167.       FDS.Update
  168.       cGrid.Col = c
  169.       cGrid = gstZoomData
  170.     End If
  171.   End If
  172.   GoTo ZoomEnd
  173. ZoomErr:
  174.   ShowError
  175.   Resume ZoomEnd
  176. ZoomEnd:
  177. End Sub
  178. Sub cGrid_KeyUp (KeyCode As Integer, Shift As Integer)
  179.   'zoom on F4 key press
  180.   If KeyCode = &H73 Then   'F4
  181.     cGrid_DblClick
  182.   End If
  183. End Sub
  184. Sub CloseButton_Click ()
  185.   Unload Me
  186. End Sub
  187. Sub FilterButton_Click ()
  188.   On Error GoTo FilterErr
  189.   Dim ds1 As Dynaset, ds2 As Dynaset
  190. '  Dim ds1 As snapshot, ds2 As snapshot
  191.   Dim FilterStr As String
  192.   Dim numbrows As Long    'local number of rows
  193.   Set ds1 = FDS            'save the dynaset
  194.   FilterStr = InputBox("Enter Filter Expression:")
  195.   If Len(FilterStr) = 0 Then Exit Sub
  196.   FDS.Filter = FilterStr
  197.   Set ds2 = FDS.CreateDynaset()            'establish the filter
  198. '  Set ds2 = FDS.CreateSnapshot()            'establish the filter
  199.   Set FDS = ds2            'assign back to original dynaset object
  200.   'everything must be okay so redisplay form on 1st record
  201.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  202. '  FNumbRows = GetNumbRecsSS(FDS)          'query numb of recs
  203.    If FNumbRows = -1 Then
  204.      'error occurred but go on anyway
  205.      'because row count is non-critical
  206.      caption = "Dynaset: " & FTblName
  207.      numbrows = gwMaxGridRows
  208.      FCurrentRow = numbrows
  209.    ElseIf FNumbRows = 0 Then
  210.      Beep
  211.      MsgBox "No Records found!", 48
  212.      Unload Me
  213.      Exit Sub
  214.    ElseIf FNumbRows > gwMaxGridRows Then
  215.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " total rows]"
  216.      numbrows = gwMaxGridRows
  217.      FCurrentRow = numbrows
  218.    Else
  219.      numbrows = FNumbRows
  220.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " rows]"
  221.    End If
  222.   If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  223.     Unload Me
  224.     Exit Sub
  225.   End If
  226.   GoTo FilterEnd
  227. FilterErr:
  228.   ShowError
  229.   Set FDS = ds1            're-assign back to original
  230.   Resume FilterEnd
  231. FilterEnd:
  232. End Sub
  233. Sub FindButton_Click ()
  234.    Dim i As Integer, r As Integer, c As Integer
  235.    On Error GoTo FindErr
  236.    'load the column names into the find form
  237.    'the 1st time it is loaded
  238.    If FFindForm.cFieldList.ListCount = 0 Then
  239.      FFindForm.cFieldList.Clear
  240.      r = cGrid.Row
  241.      c = cGrid.Col
  242.      cGrid.Row = 0
  243.      cGrid.Col = 0
  244.      For i = 1 To cGrid.Cols - 1
  245.        cGrid.Col = cGrid.Col + 1
  246.        FFindForm.cFieldList.AddItem cGrid.Text
  247.      Next
  248.      cGrid.Row = r
  249.      cGrid.Col = c
  250.    End If
  251. FindStart:       'used to loop around on not found
  252.    'reset the flags
  253.    gfFindFailed = False
  254.    gfFromTableView = True
  255.    MsgBar "Enter Search Parameters", False
  256.    FFindForm.Show MODAL
  257.    MsgBar "Searching for record", True
  258.    If gfFindFailed = True Then Exit Sub
  259.    FNotFound = False
  260.    SetHourglass Me
  261.    'search for the record
  262.    cGrid.SetFocus        'start at the top
  263.    SendKeys "^{Home}"
  264.    cGrid.Col = 1
  265.    cGrid.Row = 0
  266.    'move the right column
  267.    While cGrid.Text <> UCase(gstFindField)
  268.      If cGrid.Col = cGrid.Cols Then 'reached max col
  269.      Else
  270.        cGrid.Col = cGrid.Col + 1
  271.        SendKeys "{Right}"
  272.      End If
  273.    Wend
  274.    cGrid.Row = 1
  275.    While cGrid.Row < cGrid.Rows - 1
  276.        If gfFindMatch = False Then
  277.          Select Case gstFindOp
  278.            Case "="
  279.              If UCase(cGrid.Text) = UCase(gstFindExpr) Then GoTo AfterWhile
  280.            Case "<>"
  281.              If UCase(cGrid.Text) <> UCase(gstFindExpr) Then GoTo AfterWhile
  282.            Case ">="
  283.              If UCase(cGrid.Text) >= UCase(gstFindExpr) Then GoTo AfterWhile
  284.            Case "<="
  285.              If UCase(cGrid.Text) <= UCase(gstFindExpr) Then GoTo AfterWhile
  286.            Case ">"
  287.              If UCase(cGrid.Text) > UCase(gstFindExpr) Then GoTo AfterWhile
  288.            Case "<"
  289.              If UCase(cGrid.Text) < UCase(gstFindExpr) Then GoTo AfterWhile
  290.            Case "Like"
  291.              If UCase(cGrid.Text) Like UCase(gstFindExpr) Then GoTo AfterWhile
  292.          End Select
  293.        Else
  294.          Select Case gstFindOp
  295.            Case "="
  296.              If cGrid.Text = gstFindExpr Then GoTo AfterWhile
  297.            Case "<>"
  298.              If cGrid.Text <> gstFindExpr Then GoTo AfterWhile
  299.            Case ">="
  300.              If cGrid.Text >= gstFindExpr Then GoTo AfterWhile
  301.            Case "<="
  302.              If cGrid.Text <= gstFindExpr Then GoTo AfterWhile
  303.            Case ">"
  304.              If cGrid.Text > gstFindExpr Then GoTo AfterWhile
  305.            Case "<"
  306.              If cGrid.Text < gstFindExpr Then GoTo AfterWhile
  307.            Case "Like"
  308.              If cGrid.Text Like gstFindExpr Then GoTo AfterWhile
  309.          End Select
  310.        End If
  311.      cGrid.Row = cGrid.Row + 1
  312.      SendKeys "{Down}"
  313.    Wend
  314.    FNotFound = True       'didn't find it
  315. AfterWhile:
  316.    ResetMouse Me
  317.    'show the first record
  318.    If FNotFound Then
  319.      Beep
  320.      MsgBox "Record Not Found", 48
  321.      GoTo FindStart
  322.    End If
  323.    DoEvents
  324.    cGrid.SelStartRow = cGrid.Row
  325.    cGrid.SelStartCol = 1
  326.    cGrid.SelEndRow = cGrid.Row
  327.    cGrid.SelEndCol = FDS.Fields.Count
  328.    GoTo FindEnd
  329. FindErr:
  330.    ResetMouse Me
  331.    ShowError
  332.    Resume FindEnd
  333. FindEnd:
  334.    MsgBar NULL_STR, False
  335. End Sub
  336. Sub FirstButton_Click ()
  337.    Dim numbrows As Long         'number of rows
  338.    On Error GoTo GoFirstError
  339.    SetHourglass Me
  340.    MsgBar "Going to first record", True
  341.    cGrid.SetFocus
  342.    cGrid.Row = 1
  343.    cGrid.Col = 0
  344.    'get current starting row in grid
  345.    If cGrid.Text <> "1" Then
  346.      FDS.Close
  347.      Set FDS = gCurrentDB.CreateDynaset(FDS.Name)
  348. '     Set FDS = gCurrentDB.CreateSnapshot(FDS.Name)
  349.      FNumbRows = GetNumbRecs(FDS)
  350. '     FNumbRows = GetNumbRecsSS(FDS)
  351.      If FNumbRows > gwMaxGridRows Then
  352.        numbrows = gwMaxGridRows
  353.        FCurrentRow = numbrows
  354.      Else
  355.        numbrows = FNumbRows
  356.      End If
  357.      If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  358.        Unload Me
  359.        Exit Sub
  360.      End If
  361.   End If
  362.   cGrid.Col = 1
  363.   SendKeys "{Home}"
  364.   GoTo GoFirstEnd
  365. GoFirstError:
  366.   ShowError
  367.   Resume GoFirstEnd
  368. GoFirstEnd:
  369.   ResetMouse Me
  370.   MsgBar NULL_STR, False
  371. End Sub
  372. Sub Form_Load ()
  373.    Dim t As TableDef       'local table structure
  374.    Dim sp As Integer       'starting point of table name
  375.    Dim ep As Integer       'ending point of table name
  376.    Dim wh As String        'where clause
  377.    Dim i As Integer, j As Integer
  378.    Dim fn As String        'field name
  379.    Dim rc As Integer       'record count
  380.    Dim numbrows As Long    'local number of rows
  381.    Dim qd As QueryDef      'querydef for parameterized query
  382.    Dim p_query As Integer  'param query flag
  383.    Dim p_val As String     'param value
  384.    Dim Start1, Finish1, Start2, Finish2
  385.    On Error GoTo DynasetErr
  386.    SetHourglass Me
  387.    MsgBar "Opening Dynaset", True
  388.    'assign the temp string with the select statement
  389.    'if it is not empty, otherwise, use the table list name
  390.    If gfFromSQL = True Then
  391.      If Len(gstDynaString) = 0 Then
  392.        FDynSt = fSQL.cSQLStatement
  393.      Else
  394.        FDynSt = gstDynaString
  395.      End If
  396.    Else
  397.      FDynSt = fTables.cTableList
  398.    End If
  399.    'check for parameters
  400.    If InStr(FDynSt, "PARAM1") > 0 Or InStr(gstDynaString, "PARAM1") > 0 Then
  401.      'figure out if it is a saved querydef
  402.      If Mid(UCase(FDynSt), 1, 7) = "SELECT " Then
  403.        Set qd = gCurrentDB.CreateQueryDef("temp_qd", FDynSt)
  404.        p_query = 1
  405.      Else
  406.        Set qd = gCurrentDB.OpenQueryDef(fTables.cTableList)
  407.        p_query = 2
  408.      End If
  409.      'get the parameter value(s)
  410.      For i = 1 To 4
  411.        p_val = ""
  412.        p_val = InputBox("Enter the value for parameter " & i)
  413.        Select Case i
  414.          Case 1
  415.            qd!PARAM1 = p_val
  416.          Case 2
  417.            qd!PARAM2 = p_val
  418.          Case 3
  419.            qd!PARAM3 = p_val
  420.          Case 4
  421.            qd!PARAM4 = p_val
  422.        End Select
  423.        If InStr(FDynSt, "PARAM" & i + 1) = 0 And InStr(gstDynaString, "PARAM" & i + 1) = 0 Then Exit For
  424.      Next
  425.    End If
  426.    'attemp to open the dynaset
  427.    Start1 = TimeGetTime()
  428.    If gfFromSQL = True Then
  429.      If VDMDI.cPassThru.Visible = True And VDMDI.cPassThru = 1 Then
  430.        Set FDS = gCurrentDB.CreateDynaset(FDynSt, VBDA_SQLPASSTHROUGH)
  431.      Else
  432.        Set FDS = gCurrentDB.CreateDynaset(FDynSt)
  433.      End If
  434.    Else
  435.      If p_query = 0 Then
  436.        If VDMDI.cPassThru.Visible = True And VDMDI.cPassThru = 1 Then
  437.          FDynSt = "select * from " & StripOwner(FDynSt)
  438.          Set FDS = gCurrentDB.CreateDynaset(FDynSt, VBDA_SQLPASSTHROUGH)
  439.        Else
  440.          Set FDS = gCurrentDB.CreateDynaset(FDynSt)
  441.        End If
  442.      Else
  443.        Set FDS = qd.CreateDynaset()
  444.        qd.Close
  445.        If p_query = 1 Then gCurrentDB.DeleteQueryDef "temp_qd"
  446.      End If
  447.    End If
  448.    Finish1 = TimeGetTime()
  449.    Start2 = TimeGetTime()
  450.    'parse off table name to store in global gstTblName
  451.    wh = NULL_STR
  452.    sp = InStr(1, UCase(FDynSt), "FROM")
  453.    If sp > 0 Then
  454.      'must be a "select from" statement
  455.      sp = sp + 5
  456.      For ep = sp To Len(FDynSt)
  457.        'search for a space or the end of FDynSt
  458.        If Mid$(FDynSt, ep, 1) = " " Then
  459.          'get where clause if there is one
  460.          wh = Mid$(FDynSt, sp, Len(FDynSt) - sp + 1)
  461.          Exit For
  462.        End If
  463.      Next
  464.      FTblName = UCase(Mid$(FDynSt, sp, ep - sp))
  465.      If Len(wh) = 0 Then wh = FTblName
  466.    Else
  467.      'must be a table name only
  468.      FTblName = UCase(FDynSt)
  469.      wh = FTblName
  470.    End If
  471.    FDynaString = wh
  472.    'show the first record
  473.    FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  474.    If FNumbRows = -1 Then
  475.      'error occurred but go on anyway
  476.      'because row count is non-critical
  477.      caption = "Dynaset: " & FTblName
  478.      numbrows = gwMaxGridRows
  479.      FCurrentRow = numbrows
  480.    ElseIf FNumbRows = 0 Then
  481.      Beep
  482.      MsgBox "No Records found!", 48
  483.      ResetMouse Me
  484.      Unload Me
  485.      Exit Sub
  486.    ElseIf FNumbRows > gwMaxGridRows Then
  487.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " total rows]"
  488.      numbrows = gwMaxGridRows
  489.      FCurrentRow = numbrows
  490.    Else
  491.      numbrows = FNumbRows
  492.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " rows]"
  493.    End If
  494.    If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  495.      Unload Me
  496.      Exit Sub
  497.    End If
  498.    Height = 3800
  499.    Width = 5300
  500.    Left = 1000
  501.    Top = 1000
  502.    Finish2 = TimeGetTime()
  503.    If VDMDI.PrefShowPerf.Checked Then
  504.      Me.Show
  505.      MsgBox FNumbRows & " rows found in " & (Finish1 - Start1) / 1000 & " seconds!" & Chr(13) & Chr(10) & (Finish2 - Start2) / 1000 & " seconds to Load Grid!", 48
  506.    End If
  507.    GoTo OkayEnd
  508. DynasetErr:
  509.    If p_query = 1 Then
  510.      gCurrentDB.DeleteQueryDef "temp_qd"
  511.    End If
  512.    ShowError
  513.    ResetMouse Me
  514.    MsgBar NULL_STR, False
  515.    Unload Me
  516.    Exit Sub
  517.    Resume OkayEnd
  518. OkayEnd:
  519.    ResetMouse Me
  520.    MsgBar NULL_STR, False
  521. End Sub
  522. Sub Form_Resize ()
  523.   On Error Resume Next
  524.   'resize grid to window
  525.   If WindowState <> 1 Then   'not minimized
  526.     cGrid.Height = Height - 900
  527.     cGrid.Width = Width - 100
  528.   End If
  529. End Sub
  530. Sub Form_Unload (Cancel As Integer)
  531.   On Error Resume Next
  532.   'unload the find form
  533.   Unload FFindForm
  534.   'close the associated dynaset
  535.   FDS.Close
  536.   MsgBar NULL_STR, False
  537. End Sub
  538. Sub MoreButton_Click ()
  539.   Dim ret As Integer   'return value from loadgrid
  540.   On Error Resume Next
  541.   MsgBar "Getting more records", True
  542.   If FDS.EOF <> True Then
  543.     SetHourglass Me
  544.     ret = LoadGrid(cGrid, FDS, FDynSt, gwMaxGridRows, FCurrentRow)
  545.     If ret = False Then
  546.       'failed so bail out of form
  547.       FDS.Close
  548.       Unload Me
  549.     End If
  550.     'set new current row
  551.     FCurrentRow = FCurrentRow + ret
  552.     ResetMouse Me
  553.   End If
  554.   MsgBar NULL_STR, False
  555. End Sub
  556. Sub NextButton_Click ()
  557.    Dim c As Integer      'current column
  558.    On Error GoTo GoNextError
  559.    c = cGrid.Col
  560.    cGrid.Col = 0
  561.    If Len(cGrid.Text) = 0 Then
  562.      Beep
  563.    ElseIf cGrid.Row = gwMaxGridRows Then
  564.      MoreButton_Click
  565.    Else
  566.      cGrid.SetFocus
  567.      SendKeys "{Down}"
  568.    End If
  569.    cGrid.Col = c
  570.    GoTo GoNextEnd
  571. GoNextError:
  572.    ShowError
  573.    Resume GoNextEnd
  574. GoNextEnd:
  575. End Sub
  576. 'needed for multi-user situations so
  577. 'new records can be viewed imediately
  578. Sub RefreshButton_Click ()
  579.    Dim numbrows As Long
  580.    On Error GoTo RefreshError
  581.    MsgBar "Reopening Dynaset", True
  582.    SetHourglass Me
  583.    Set FDS = gCurrentDB.CreateDynaset(FDS.Name)
  584. '   Set FDS = gCurrentDB.CreateSnapshot(FDS.Name)
  585.    FNumbRows = GetNumbRecs(FDS)
  586. '   FNumbRows = GetNumbRecsSS(FDS)
  587.    If FNumbRows = -1 Then
  588.      'error occurred but go on anyway
  589.      'because row count is non-critical
  590.      caption = "Dynaset: " & FTblName
  591.      numbrows = gwMaxGridRows
  592.      FCurrentRow = numbrows
  593.    ElseIf FNumbRows = 0 Then
  594.      Beep
  595.      MsgBox "No Records found!", 48
  596.      Unload Me
  597.    ElseIf FNumbRows > gwMaxGridRows Then
  598.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " total rows]"
  599.      numbrows = gwMaxGridRows
  600.      FCurrentRow = numbrows
  601.    Else
  602.      numbrows = FNumbRows
  603.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " rows]"
  604.    End If
  605.    If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  606.      Unload Me
  607.      Exit Sub
  608.    End If
  609.   GoTo RefreshEnd
  610. RefreshError:
  611.   ShowError
  612.   Resume RefreshEnd
  613. RefreshEnd:
  614.   ResetMouse Me
  615.   MsgBar NULL_STR, False
  616. End Sub
  617. Sub SortButton_Click ()
  618.   On Error GoTo SortErr
  619.   Dim ds1 As Dynaset, ds2 As Dynaset
  620. '  Dim ds1 As snapshot, ds2 As snapshot
  621.   Dim SortStr As String
  622.   Dim numbrows As Long    'local number of rows
  623.   Set ds1 = FDS            'save the dynaset
  624.   SortStr = InputBox("Enter Sort Column:")
  625.   If Len(SortStr) = 0 Then Exit Sub
  626.   FDS.Sort = SortStr
  627.   Set ds2 = FDS.CreateDynaset()            'establish the Sort
  628. '  Set ds2 = FDS.CreateSnapshot()            'establish the Sort
  629.   Set FDS = ds2            'assign back to original dynaset object
  630.   'everything must be okay so redisplay form on 1st record
  631.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  632. '  FNumbRows = GetNumbRecsSS(FDS)          'query numb of recs
  633.    If FNumbRows = -1 Then
  634.      'error occurred but go on anyway
  635.      'because row count is non-critical
  636.      caption = "Dynaset: " & FTblName
  637.      numbrows = gwMaxGridRows
  638.      FCurrentRow = numbrows
  639.    ElseIf FNumbRows = 0 Then
  640.      Beep
  641.      MsgBox "No Records found!", 48
  642.      Unload Me
  643.      Exit Sub
  644.    ElseIf FNumbRows > gwMaxGridRows Then
  645.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " total rows]"
  646.      numbrows = gwMaxGridRows
  647.      FCurrentRow = numbrows
  648.    Else
  649.      numbrows = FNumbRows
  650.      caption = "Dynaset: " & FTblName & " [" & CStr(FNumbRows) & " rows]"
  651.    End If
  652.   If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  653.     Unload Me
  654.     Exit Sub
  655.   End If
  656.   GoTo SortEnd
  657. SortErr:
  658.   ShowError
  659.   Set FDS = ds1            're-assign back to original
  660.   Resume SortEnd
  661. SortEnd:
  662. End Sub
  663.